package com.qnw.CardGroupManagement.management;
import android.database.sqlite.*;
import java.util.*;
import com.qnw.CardGroupManagement.*;
import android.util.*;

public class CdbManagement
{
	private static CdbManagement cm=new CdbManagement();
	private SQLiteDatabase cdb;
	private List<Card> xzcard=new ArrayList<Card>();
	private List<String> xzcdb=new ArrayList<String>();
	private int dqcdb=-1;
	List<Map<String,Object>> cdbList=new ArrayList<Map<String,Object>>();
	
	
	
	private CdbManagement(){
		
		
	}

	public void setCdbList(List<Map<String, Object>> cdbList)
	{
		this.cdbList = cdbList;
	}

	public List<Map<String, Object>> getCdbList()
	{
		return cdbList;
	}

	public void setDqcdb(int dqcdb)
	{

		if (this.dqcdb != -1) {
			if (dqcdb < cdbList.size()) {
				Map<String,Object> map=cdbList.get(this.dqcdb);
				map.put("dq", false);
				cdbList.set(this.dqcdb, map);
			}
		}
		if (dqcdb != -1) {
			Map<String,Object> map1=cdbList.get(dqcdb);	
			map1.put("dq", true);	
			cdbList.set(dqcdb, map1);

		}

		this.dqcdb = dqcdb;
	}

	public int getDqcdb()
	{
		return dqcdb;
	}

	public void setXzcdb(List<String> xzcdb)
	{
		this.xzcdb = xzcdb;
	}

	public List<String> getXzcdb()
	{
		return xzcdb;
	}

	public void setXzcard(List<Card> xzcard)
	{
		this.xzcard = xzcard;
	}

	public List<Card> getXzcard()
	{
		return xzcard;
	}

	public void setCdb(SQLiteDatabase cdb)
	{
		//如果数据库不为空则关闭数据库
		if(this.cdb!=null){
			this.cdb.close();
		}
		this.cdb = cdb;
	}
	
	public void setCdb(String path)
	{
		//如果数据库不为空则关闭数据库
		if(cdb!=null){
			closeCdb();
		}
		cdb=SQLiteDatabase.openOrCreateDatabase(path, null);
	}
	
	public void closeCdb(){
		if(cdb!=null){
		cdb.close();
		}
		cdb=null;
		//dqcdb=-1;
	}
	
	public boolean conCard(String km){
		for(Card c:xzcard){
			if(c.getId().equals(km)){
				return true;
			}
		}
		return false;
	}
	
	public boolean conCdb(String path){
		for(String s:xzcdb){
			if(s.equals(path)){
				return true;
			}
		}
		return false;
	}
	
	public void removeCard(String km){
		for(Card c:xzcard){
			if(c.getId().equals(km)){
				xzcard.remove(c);
				return;
			}
		}
	}
	
	public SQLiteDatabase getCdb(){
		return cdb;
	}

	public static CdbManagement getdx(){
		return cm;
	}
	
	
	
}
